package com.ohc.leetcode.链表;

import java.util.ArrayList;

/**
 * 2022年6月20日15:17:22
 * https://leetcode.cn/problems/kth-node-from-end-of-list-lcci/
 */
public class 面试题0202返回倒数第k个节点 {
    public static class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }

    public static int kthToLast(ListNode head, int k) {
        ArrayList<Integer> list = new ArrayList<>();
        while (head != null) {
            list.add(head.val);
        }
        return list.get(list.size() - 1 - k);
    }

    public static void main(String[] args) {

    }
}
